package com.xc.h05.controller.wyl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Mynotice;
import com.xc.h05.service.wyl.MyNoticeService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/mynotice")
public class MyNoticeController {
    @Autowired
    private MyNoticeService myNoticeService;
    @GetMapping("/find")
    public R find(){
        List<Mynotice> all = myNoticeService.find();
        return R.ok(all);
    }
    @GetMapping("/findAll")
    public R findAll(Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<Mynotice> all = myNoticeService.findAll();
        PageInfo<Mynotice> pageInfo = new PageInfo<>(all);
        return R.ok(pageInfo);
    }
    @PostMapping("/add")
    public R add(@RequestBody Mynotice mynotice){
        int i = myNoticeService.add(mynotice);
        if (i>0){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @DeleteMapping("/delete")
    public R delete(Long id){

        int i = myNoticeService.delete(id);
        if (i>0){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @PutMapping("/update")
    public R update(@RequestBody Mynotice mynotice){
        int i = myNoticeService.update(mynotice);
        if (i>0){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }


}
